//
//  RecommendListViewController.m
//  YoucApp
//
//  Created by Liam on 11/15/12.
//
//

#import "RecommendListViewController.h"
#import "RecommendCell.h"
#import "YAObjRecommend.h"

@interface RecommendListViewController ()

@end

@implementation RecommendListViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - override method

- (NSString *)gameListNotificationName
{
    return LMGetRecommendListDidFinishedNotification;
}

- (BOOL)loadList:(NSInteger)start limit:(NSInteger)limit
{
    LMListParam *param = [[[LMListParam alloc] init] autorelease];
    param.start = start;
    param.limit = limit;
    param.context = self;
    
    [[ListManager instance] getRecommendList:param forceLoad:YES];
	
	return YES;
}

- (NSArray *)getShowList
{
    return self.gameList;
}

- (void)getServerListDidFinished:(NSArray *)list listParam:(LMServerListParam *)listParam error:(NSError *)error
{
    if ([error code] == YoucApiErrorSuccess)
    {
        NSMutableArray *array = [NSMutableArray arrayWithArray:self.gameList];
        [array addObjectsFromArray:list];
        
        self.gameList = array;
        
        [self constructCurrentShowList];
    }
}

- (NSString *)getCellIdentifierByItem:(id)item
{
    NSString *identifier = nil;
    
    if ([item isKindOfClass:[YAObjRecommend class]])
    {
        identifier = @"RecommendCell";
    }
	else
	{
		identifier = [super getCellIdentifierByItem:item];
	}
    
    return identifier;
}

- (void)updateCell:(UITableViewCell *)cell withItem:(id)item
{
    if ([item isKindOfClass:[YAObjRecommend class]])
    {
        [self updateRecommendCell:(RecommendCell *)cell withItem:item];
    }
    else
    {
        [self updateCell:cell withItem:item];
    }
}

#pragma mark - local method

- (void)updateRecommendCell:(RecommendCell *)cell withItem:(YAObjRecommend *)item
{
    if (cell && item)
    {
        cell.serverName.text = item.serverName;
        cell.platformName.text = item.platformName;
        cell.platformUrl.text = item.platformUrl;
        [cell setServerTimeInterval:item.serverTime];
        [cell setName:item.gameName];
        [cell setImageUrl:item.gameImage];
    }
}

@end
